import 'package:flutter/material.dart';

class TestImageGrid extends StatefulWidget {
  @override
  _TestImageGridState createState() => _TestImageGridState();
}

class _TestImageGridState extends State<TestImageGrid> {
  @override
  Widget build(BuildContext context) {
    List<GridTile> widgetList = [];
    for (int index = 1; index <= 8; index++) {
      widgetList.add(
        GridTile(
          child: Image.asset("assets/car/car0$index.jpg"),
          footer: GridTileBar(
            backgroundColor: Colors.black45,
            title: Text("car0$index.jpg"),
          ),
        ),
      );
    }

    return new Scaffold(
      appBar: AppBar(
        title: Text("图片列表Grid"),
        centerTitle: true,
      ),
      backgroundColor: Colors.grey[200],
      body: GridView.count(
        crossAxisCount: 2,
        mainAxisSpacing: 4.0,
        crossAxisSpacing: 4.0,
        padding: const EdgeInsets.all(4.0),
        children: widgetList,
      ),
    );
  }
}
